<?php
namespace Home\Model;
use Think\Model;
class IkhdModel extends Model {
    protected $tableName = "withdrawals";

    protected $_validate = array(
        array('money','require','金额必须填写')
    );

    public function jine(){

        $money = $_REQUEST['money'];//用户要提现的金额
        $id = session('id');//用户id
        $where['idpu'] = $id;
        $wh['with_id'] = $id;
//        $wh['with_id'] = 7;
//        $where['idpu'] = 7;
        $time = date("Y-m-d H:i:s",time());//当前时间
        $names = M('purse')->where($where)->select();
        $idsd =  M('withdrawals')->where($wh)->select();
        $data['record'] = $time."提现".$money."元";
        $data['times'] = $time;
        $data['with_id'] = $id;
//        $data['with_id'] = 7;
        $moneys['money'] = $names[0]['money'] -$money;
        if($names[0]['money']<$money){
            $this->error ="当前余额不足!!";
            return;
        }else{
            M('purse')->where($where)->save($moneys);
            $s = M('withdrawals')->add($data);
        }
        return $s;
    }
}